<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="static/treetable/jquery.treetable.css">
    <link rel="stylesheet" href="static/treetable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="static/treetable/screen.css">
    <title>DWell CMS</title>
</head>
<body class="dashboard fixed skin-blue">
<div class="wrapper">
    <table id="tree">
        <thead>
        <tr>
            <th>Name</th>
            <th>Date modified</th>
            <th>Size</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th>AAA</th>
            <th>VVV VV</th>
            <th>CCCCC</th>
        </tr>
        <tr data-tt-id='2' data-tt-branch="true"><td><span class='folder'>CHUD</span></td><td>Folder</td><td>--</td></tr>
        <c:forEach items="${fileNodes}" var="fileNode">
            <tr data-tt-id="${fileNode.dataTTId}" data-tt-parent-id="${fileNode.dataTTParentId}" data-tt-branch="true">
                <th>${fileNode.name}</th>
                <th>${fileNode.kind}</th>
                <th>${fileNode.size}</th>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<script src="static/common/js/jquery-2.1.0.min.js"></script>
<script src="static/treetable/jquery.treetable.js"></script>
<script type="text/javascript">
    $(function(){
        $("#tree").treetable({
            expandable: true,
            onNodeExpand: function() {
                var node = this;
                // Render loader/spinner while loading
                $.ajax({
                    async: false, // Must be false, otherwise loadBranch happens after showChildren?
                    url: "/nodes/children/find",
                    data: {"id":node.id}
                }).done(function(html) {
                    console.log(html);
                    var rows = $(html).filter("tr");
                    rows.find(".directory").parents("tr").each(function() {
                        droppableSetup.apply(this);
                    })
                    table.treetable("loadBranch", node, rows);
                });
            }
        });
    });
</script>
</body>
</html>

